﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoA.Shared.Interfaces;
using Microsoft.Xna.Framework;

namespace LoA.CameraEngine.Entities {
	internal sealed class SecondPersonCameraProcessor : CameraProcessorBase {
		private Vector3 objectPosition;
		private Vector3 objectDirection;
		private Vector3 objectUp;
		private Vector3 targetOffset;

		public SecondPersonCameraProcessor(Game game) {
			this.FieldOfView = MathHelper.ToRadians(45.0f);
			this.NearPlaneDistance = 0.02f;
			this.FarPlaneDistance = 700.0f;

			this.objectPosition = Vector3.UnitY * 2;
			this.objectDirection = Vector3.UnitX;
			this.targetOffset = new Vector3(0.0f, 1.85f, 0.0f);

			this.UpdateViewMatrix( );
		}

		public Vector3 ObjectPosition { get { return this.objectPosition; } set { this.objectPosition = value; } }
		public Vector3 ObjectDirection { get { return this.objectDirection; } set { this.objectDirection = value; } }
		public Vector3 ObjectUp { get { return this.objectUp; } set { this.objectUp = value; } }
		public Vector3 TargetOffset { get { return this.targetOffset; } set { this.targetOffset = value; } }

		private void UpdateViewMatrix( ) {
			this.ViewMatrix = Matrix.CreateLookAt(
				this.ObjectPosition - this.ObjectDirection + this.TargetOffset,
				this.ObjectPosition + this.TargetOffset,
				Vector3.Up
			);
		}

		public override void Update(GameTime gameTime, IInput inputEngine) {
			this.UpdateViewMatrix( );
		}
	}
}
